﻿namespace Microsoft.SharePoint.Client
{
    using System;
    using System.ComponentModel;

    [ScriptType("SP.Field", ServerTypeId="{c4121b04-0f57-4b1d-a145-d25426b16480}")]
    public class Field : ClientObject
    {
        [EditorBrowsable(EditorBrowsableState.Never)]
        public Field(ClientRuntimeContext Context, ObjectPath ObjectPath) : base(Context, ObjectPath)
        {
        }

        [Remote]
        public void DeleteObject()
        {
            ClientAction query = new ClientActionInvokeMethod(this, "DeleteObject", null);
            base.Context.AddQuery(query);
            base.RemoveFromParentCollection();
        }

        protected override bool InitOnePropertyFromJson(string peekedName, JsonReader reader)
        {
            bool flag = base.InitOnePropertyFromJson(peekedName, reader);
            if (!flag)
            {
                switch (peekedName)
                {
                    case "TypeDisplayName":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["TypeDisplayName"] = reader.ReadString();
                        return flag;

                    case "TypeShortDescription":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["TypeShortDescription"] = reader.ReadString();
                        return flag;

                    case "InternalName":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["InternalName"] = reader.ReadString();
                        return flag;

                    case "Id":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["Id"] = reader.ReadGuid();
                        return flag;

                    case "EnforceUniqueValues":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["EnforceUniqueValues"] = reader.ReadBoolean();
                        return flag;

                    case "Title":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["Title"] = reader.ReadString();
                        return flag;

                    case "Description":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["Description"] = reader.ReadString();
                        return flag;

                    case "Group":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["Group"] = reader.ReadString();
                        return flag;

                    case "DefaultValue":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["DefaultValue"] = reader.ReadString();
                        return flag;

                    case "ValidationFormula":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["ValidationFormula"] = reader.ReadString();
                        return flag;

                    case "ValidationMessage":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["ValidationMessage"] = reader.ReadString();
                        return flag;

                    case "FieldTypeKind":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["FieldTypeKind"] = reader.ReadEnum<FieldType>();
                        return flag;

                    case "TypeAsString":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["TypeAsString"] = reader.ReadString();
                        return flag;

                    case "FromBaseType":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["FromBaseType"] = reader.ReadBoolean();
                        return flag;

                    case "Sealed":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["Sealed"] = reader.ReadBoolean();
                        return flag;

                    case "CanBeDeleted":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["CanBeDeleted"] = reader.ReadBoolean();
                        return flag;

                    case "Required":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["Required"] = reader.ReadBoolean();
                        return flag;

                    case "ReadOnlyField":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["ReadOnlyField"] = reader.ReadBoolean();
                        return flag;

                    case "Hidden":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["Hidden"] = reader.ReadBoolean();
                        return flag;

                    case "Direction":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["Direction"] = reader.ReadString();
                        return flag;

                    case "Sortable":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["Sortable"] = reader.ReadBoolean();
                        return flag;

                    case "Filterable":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["Filterable"] = reader.ReadBoolean();
                        return flag;

                    case "SchemaXml":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["SchemaXml"] = reader.ReadString();
                        return flag;

                    case "StaticName":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["StaticName"] = reader.ReadString();
                        return flag;

                    case "Scope":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["Scope"] = reader.ReadString();
                        return flag;
                }
            }
            return flag;
        }

        [Remote]
        public virtual void Update()
        {
            ClientAction query = new ClientActionInvokeMethod(this, "Update", null);
            base.Context.AddQuery(query);
        }

        [Remote]
        public void UpdateAndPushChanges(bool pushChangesToLists)
        {
            ClientAction query = new ClientActionInvokeMethod(this, "UpdateAndPushChanges", new object[] { pushChangesToLists });
            base.Context.AddQuery(query);
        }

        [Remote]
        public bool CanBeDeleted
        {
            get
            {
                base.CheckUninitializedProperty("CanBeDeleted");
                return (bool) base.ObjectData.Properties["CanBeDeleted"];
            }
        }

        [Remote]
        public string DefaultValue
        {
            get
            {
                base.CheckUninitializedProperty("DefaultValue");
                return (string) base.ObjectData.Properties["DefaultValue"];
            }
            set
            {
                base.ObjectData.Properties["DefaultValue"] = value;
                if (base.Context != null)
                {
                    base.Context.AddQuery(new ClientActionSetProperty(this, "DefaultValue", value));
                }
            }
        }

        [Remote]
        public string Description
        {
            get
            {
                base.CheckUninitializedProperty("Description");
                return (string) base.ObjectData.Properties["Description"];
            }
            set
            {
                base.ObjectData.Properties["Description"] = value;
                if (base.Context != null)
                {
                    base.Context.AddQuery(new ClientActionSetProperty(this, "Description", value));
                }
            }
        }

        [Remote]
        public string Direction
        {
            get
            {
                base.CheckUninitializedProperty("Direction");
                return (string) base.ObjectData.Properties["Direction"];
            }
            set
            {
                base.ObjectData.Properties["Direction"] = value;
                if (base.Context != null)
                {
                    base.Context.AddQuery(new ClientActionSetProperty(this, "Direction", value));
                }
            }
        }

        [Remote]
        public bool EnforceUniqueValues
        {
            get
            {
                base.CheckUninitializedProperty("EnforceUniqueValues");
                return (bool) base.ObjectData.Properties["EnforceUniqueValues"];
            }
            set
            {
                base.ObjectData.Properties["EnforceUniqueValues"] = value;
                if (base.Context != null)
                {
                    base.Context.AddQuery(new ClientActionSetProperty(this, "EnforceUniqueValues", value));
                }
            }
        }

        [Remote]
        public FieldType FieldTypeKind
        {
            get
            {
                base.CheckUninitializedProperty("FieldTypeKind");
                return (FieldType) base.ObjectData.Properties["FieldTypeKind"];
            }
            set
            {
                base.ObjectData.Properties["FieldTypeKind"] = value;
                if (base.Context != null)
                {
                    base.Context.AddQuery(new ClientActionSetProperty(this, "FieldTypeKind", value));
                }
            }
        }

        [Remote]
        public bool Filterable
        {
            get
            {
                base.CheckUninitializedProperty("Filterable");
                return (bool) base.ObjectData.Properties["Filterable"];
            }
        }

        [Remote]
        public bool FromBaseType
        {
            get
            {
                base.CheckUninitializedProperty("FromBaseType");
                return (bool) base.ObjectData.Properties["FromBaseType"];
            }
        }

        [Remote]
        public string Group
        {
            get
            {
                base.CheckUninitializedProperty("Group");
                return (string) base.ObjectData.Properties["Group"];
            }
            set
            {
                if (base.Context.ValidateOnClient)
                {
                    if (value == null)
                    {
                        throw ClientUtility.CreateArgumentNullException("value");
                    }
                    if ((value != null) && (value.Length == 0))
                    {
                        throw ClientUtility.CreateArgumentException("value");
                    }
                    if ((value != null) && (value.Length > 0x80))
                    {
                        throw ClientUtility.CreateArgumentException("value");
                    }
                }
                base.ObjectData.Properties["Group"] = value;
                if (base.Context != null)
                {
                    base.Context.AddQuery(new ClientActionSetProperty(this, "Group", value));
                }
            }
        }

        [Remote]
        public bool Hidden
        {
            get
            {
                base.CheckUninitializedProperty("Hidden");
                return (bool) base.ObjectData.Properties["Hidden"];
            }
            set
            {
                base.ObjectData.Properties["Hidden"] = value;
                if (base.Context != null)
                {
                    base.Context.AddQuery(new ClientActionSetProperty(this, "Hidden", value));
                }
            }
        }

        [Remote]
        public Guid Id
        {
            get
            {
                base.CheckUninitializedProperty("Id");
                return (Guid) base.ObjectData.Properties["Id"];
            }
        }

        [Remote]
        public string InternalName
        {
            get
            {
                base.CheckUninitializedProperty("InternalName");
                return (string) base.ObjectData.Properties["InternalName"];
            }
        }

        [Remote]
        public bool ReadOnlyField
        {
            get
            {
                base.CheckUninitializedProperty("ReadOnlyField");
                return (bool) base.ObjectData.Properties["ReadOnlyField"];
            }
            set
            {
                base.ObjectData.Properties["ReadOnlyField"] = value;
                if (base.Context != null)
                {
                    base.Context.AddQuery(new ClientActionSetProperty(this, "ReadOnlyField", value));
                }
            }
        }

        [Remote]
        public bool Required
        {
            get
            {
                base.CheckUninitializedProperty("Required");
                return (bool) base.ObjectData.Properties["Required"];
            }
            set
            {
                base.ObjectData.Properties["Required"] = value;
                if (base.Context != null)
                {
                    base.Context.AddQuery(new ClientActionSetProperty(this, "Required", value));
                }
            }
        }

        [Remote]
        public string SchemaXml
        {
            get
            {
                base.CheckUninitializedProperty("SchemaXml");
                return (string) base.ObjectData.Properties["SchemaXml"];
            }
            set
            {
                base.ObjectData.Properties["SchemaXml"] = value;
                if (base.Context != null)
                {
                    base.Context.AddQuery(new ClientActionSetProperty(this, "SchemaXml", value));
                }
            }
        }

        [Remote]
        public string Scope
        {
            get
            {
                base.CheckUninitializedProperty("Scope");
                return (string) base.ObjectData.Properties["Scope"];
            }
        }

        [Remote]
        public bool Sealed
        {
            get
            {
                base.CheckUninitializedProperty("Sealed");
                return (bool) base.ObjectData.Properties["Sealed"];
            }
        }

        [Remote]
        public bool Sortable
        {
            get
            {
                base.CheckUninitializedProperty("Sortable");
                return (bool) base.ObjectData.Properties["Sortable"];
            }
        }

        [Remote]
        public string StaticName
        {
            get
            {
                base.CheckUninitializedProperty("StaticName");
                return (string) base.ObjectData.Properties["StaticName"];
            }
            set
            {
                base.ObjectData.Properties["StaticName"] = value;
                if (base.Context != null)
                {
                    base.Context.AddQuery(new ClientActionSetProperty(this, "StaticName", value));
                }
            }
        }

        [Remote]
        public string Title
        {
            get
            {
                base.CheckUninitializedProperty("Title");
                return (string) base.ObjectData.Properties["Title"];
            }
            set
            {
                base.ObjectData.Properties["Title"] = value;
                if (base.Context != null)
                {
                    base.Context.AddQuery(new ClientActionSetProperty(this, "Title", value));
                }
            }
        }

        [Remote]
        public string TypeAsString
        {
            get
            {
                base.CheckUninitializedProperty("TypeAsString");
                return (string) base.ObjectData.Properties["TypeAsString"];
            }
            set
            {
                if (base.Context.ValidateOnClient)
                {
                    if (value == null)
                    {
                        throw ClientUtility.CreateArgumentNullException("value");
                    }
                    if ((value != null) && (value.Length == 0))
                    {
                        throw ClientUtility.CreateArgumentException("value");
                    }
                }
                base.ObjectData.Properties["TypeAsString"] = value;
                if (base.Context != null)
                {
                    base.Context.AddQuery(new ClientActionSetProperty(this, "TypeAsString", value));
                }
            }
        }

        [Remote]
        public string TypeDisplayName
        {
            get
            {
                base.CheckUninitializedProperty("TypeDisplayName");
                return (string) base.ObjectData.Properties["TypeDisplayName"];
            }
        }

        [Remote]
        public string TypeShortDescription
        {
            get
            {
                base.CheckUninitializedProperty("TypeShortDescription");
                return (string) base.ObjectData.Properties["TypeShortDescription"];
            }
        }

        [Remote]
        public string ValidationFormula
        {
            get
            {
                base.CheckUninitializedProperty("ValidationFormula");
                return (string) base.ObjectData.Properties["ValidationFormula"];
            }
            set
            {
                base.ObjectData.Properties["ValidationFormula"] = value;
                if (base.Context != null)
                {
                    base.Context.AddQuery(new ClientActionSetProperty(this, "ValidationFormula", value));
                }
            }
        }

        [Remote]
        public string ValidationMessage
        {
            get
            {
                base.CheckUninitializedProperty("ValidationMessage");
                return (string) base.ObjectData.Properties["ValidationMessage"];
            }
            set
            {
                if ((base.Context.ValidateOnClient && (value != null)) && (value.Length > 0x400))
                {
                    throw ClientUtility.CreateArgumentException("value");
                }
                base.ObjectData.Properties["ValidationMessage"] = value;
                if (base.Context != null)
                {
                    base.Context.AddQuery(new ClientActionSetProperty(this, "ValidationMessage", value));
                }
            }
        }
    }
}

